package com.truthbean.ssm.demo.test;

import com.alibaba.fastjson.JSON;
import com.truthbean.ssm.demo.domain.entity.Enroll;
import com.truthbean.ssm.demo.service.EnrollService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author Truthbean
 * @since 2015-12-17 22:10:03
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/spring/spring.xml"})
public class EnrollTester {

    private static final Logger logger = Logger.getLogger(EnrollTester.class);

    @Autowired
    private EnrollService enrollService;

    @Test
    public void testSave() {
        Enroll enroll = new Enroll(2016, "黄冈");
        logger.info(enrollService.save(enroll));
    }

    @Test
    public void testUpdateArea() {
        logger.info(enrollService.updateArea("黄石", "阳新"));
    }

    @Test
    public void testDeleteEnroll() {
        logger.info(enrollService.deleteEnroll("黄石"));
    }

    @Test
    public void testUpdateYear() {
        int oldYear = 2016;
        String enrollArea = "黄石";
        String newYear = "2017";
        logger.info(enrollService.updateYear(oldYear, enrollArea, newYear));
    }

    @Test
    public void testAddYear() {
        logger.info(enrollService.addYear("黄石", 2016));
    }

    @Test
    public void testQueryYearsOverPage() {
        logger.info(JSON.toJSON(enrollService.queryYearsOverPage(0, 12)));
    }

    @Test
    public void testQueryAllYears() {
        logger.info(JSON.toJSON(enrollService.queryAllYears()));
    }

    @Test
    public void testQueryAreasOverPage() {
        logger.info(JSON.toJSON(enrollService.queryAreasOverPage(0, 12)));
    }

    @Test
    public void testQueryAllAreas() {
        logger.info(JSON.toJSON(enrollService.queryAllAreas()));
    }

    @Test
    public void testQueryYearByArea() {
        logger.info(JSON.toJSON(enrollService.queryYearByArea("黄石")));
    }

    @Test
    public void testBatchDeleteEnroll() {
        String[] area = {"黄石"};
        logger.info(enrollService.batchDeleteEnroll(area));
    }

    @Test
    public void testBatchDeleteYear() {
        String[] area = {"天津", "河北"};
        String year = ",2012";
        logger.info(enrollService.batchDeleteYear(area, year));
    }

    @Test
    public void testBatchAddYear() {
        String[] area = {"天津", "河北"};
        int year = 2012;
        logger.info(enrollService.batchAddYear(area, year));
    }

    @Test
    public void testQueryEnrollOverPage() {
        logger.info(JSON.toJSON(enrollService.queryEnrollOverPage(0, 12)));
    }

    @Test
    public void testQueryAll() {
        logger.info(JSON.toJSON(enrollService.queryAll()));
    }

    @Test
    public void testCountEnroll() {
        logger.info(enrollService.countEnroll());
    }

    @Test
    public void testIsAreaExist() {
        logger.info(enrollService.isAreaExist("天津"));
    }
}
